package org.pzy.java.json;


import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author pzy
 */
public class Test {
    public static void main(String[] args) {
        User user = new User();
        user.setId(1);
        user.setName("a");
        User user2 = new User();
        user2.setId(1);
        user2.setName("a");
        List<User> userList = new ArrayList<>();
        userList.add(user);
        userList.add(user2);
        List<User> userList1 = userList.stream()
                .collect(Collectors.collectingAndThen(
                        Collectors.toMap(User::getId, obj -> obj, (existing, replacement) -> existing),
                        map -> new ArrayList<>(map.values())
                ));
        System.out.println(JSON.toJSONString(userList1));
    }
}
